package com.xbongbong.paas.help.factory.impl;

import com.alibaba.fastjson.JSONObject;
import com.xbongbong.paas.abstracts.AbstractOperatorFieldHandler;
import com.xbongbong.paas.domain.entity.PaasFormDataEntity;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.ItemPoJo;
import com.xbongbong.paas.help.ProFormHelp;
import com.xbongbong.paas.help.factory.OperatorFieldHandler;
import com.xbongbong.paas.pojo.OperationsPojo;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.util.ItemUtil;
import com.xbongbong.pro.businessrule.pojo.BusinessRuleInfoPojo;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * @ClassName OperatorStageHandlerImpl
 * @Description 阶段推进器字段解析
 * @Author sunshaoxiang
 * @Date 2021/12/27 11:34
 * @Version 1.0
 **/
@Component
public class OperatorStageHandlerImpl extends AbstractOperatorFieldHandler {

    @Override
    public List<Integer> fieldType() {
        return Arrays.asList(FieldTypeEnum.STAGE_THRUSTER.getType());
    }

    @Resource
    private ProFormHelp proFormHelp;

    @Override
    public Object handlerThisFormField(PaasFormDataEntity paasFormDataEntity, JSONObject data, FieldAttrEntity fieldAttrEntity, BusinessRuleInfoPojo businessRuleInfoPojo) throws XbbException {
        String corpid = businessRuleInfoPojo.getCorpid();
        Integer saasMark = businessRuleInfoPojo.getSaasMark();
        Integer businessType = businessRuleInfoPojo.getBusinessType();
        Long formId = businessRuleInfoPojo.getFormId();
        List<ItemPoJo> itemPoJos = proFormHelp.getEditStageComboItems(fieldAttrEntity, saasMark, businessType, corpid, formId, data);
        fieldAttrEntity.setItems(itemPoJos);
        return ItemUtil.getCustomItemList(fieldAttrEntity, data);
    }

    @Override
    public Object handlerTargetFormField(PaasFormDataEntity paasFormDataEntity, JSONObject data, FieldAttrEntity fieldAttrEntity, FieldAttrEntity targetField, BusinessRuleInfoPojo businessRuleInfoPojo, OperationsPojo operation) throws XbbException {
        return null;
    }

    @Override
    public Object handlerFixedValue(FieldAttrEntity targetField, BusinessRuleInfoPojo businessRuleInfoPojo, OperationsPojo operation) throws XbbException {
        return null;
    }
}
